﻿using System;
using System.Collections.Generic;
using smp.ButterflyCakes.Models.Data;

namespace smp.ButterflyCakes.Models.ViewModels.Order
{
    public class ColourPickerView
    {
        public Guid OrderId { get; set; }
        public SelectItem SelectManufacturers { get; private set; }
        public List<ColourItem> Colours { get; set; }

        public void AddManufacturers(List<string> manufacturers)
        {
            SelectManufacturers = new SelectItem("ColourManufacturers", false);
            SelectManufacturers.AddOption(new SelectOption("All", null));
            foreach (var manufacturer in manufacturers)
            {
                SelectManufacturers.AddOption(new SelectOption(manufacturer, manufacturer));
            }
        }

        public ColourPickerSelectedView Selected { get; set; }
    }

    public class ColourPickerSelectedView
    {
        private readonly List<ColourItem> _selectedColours = new List<ColourItem>();

        public int Red
        {
            get
            {
                var sum = 0;
                foreach (var colour in _selectedColours)
                {
                    sum += colour.Red;
                }
                return (int)Math.Round((double) (sum/_selectedColours.Count));
            }
        }
        public int Green
        {
            get
            {
                var sum = 0;
                foreach (var colour in _selectedColours)
                {
                    sum += colour.Green;
                }
                return (int)Math.Round((double)(sum / _selectedColours.Count));
            }
        }
        public int Blue
        {
            get
            {
                var sum = 0;
                foreach (var colour in _selectedColours)
                {
                    sum += colour.Blue;
                }
                return (int)Math.Round((double)(sum / _selectedColours.Count));
            }
        }
        public string Rgb { get { return string.Format("rgb({0}, {1}, {2})", Red, Green, Blue); } }

        public List<ColourItem> Colours { get { return _selectedColours; } }
    }
}
